int digitalPin = 0; //初始化PA0 到 PA7引脚。 // A-G、DP
int weiPin = 21; // 第一位数引脚接口
int count = -1;
int digitalShowTime = 1;

void setup() {
  // put your setup code here, to run once:

  for (int x = 0; x < 4; x++) {
    pinMode(weiPin + x, OUTPUT); //设置各位公共引脚接口为输出
    digitalWrite(weiPin + x, HIGH); //公共引脚高电平，
  }
  for (int x = 0; x < 8; x++) {
    pinMode(digitalPin + x, OUTPUT); //设置各段led引脚接口为输出
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  count++;

  if (count < 3600) { // 60:00
    for (int i = 0; i < 50; i++) {
      display(1, count / 600);
      delay(4);
      display(2, ((count % 600) / 60)+19); // +19 用来显示  0.
      delay(4);
      display(3, ((count % 600) % 60) / 10);
      delay(4);
      display(4, ((count % 600) % 60) % 10);
      delay(4);
    }
  } else {
    count = 0;
  }
}




void displayDigital(unsigned int digit) {
  unsigned char abcdefgh[][8] = {//定义一个数组，存储不同数字的abcdefgh各段的取值
    {0, 0, 0, 0, 0, 0, 1, 1}, //0
    {1, 0, 0, 1, 1, 1, 1, 1}, //1
    {0, 0, 1, 0, 0, 1, 0, 1}, //2
    {0, 0, 0, 0, 1, 1, 0, 1}, //3
    {1, 0, 0, 1, 1, 0, 0, 1}, //4
    {0, 1, 0, 0, 1, 0, 0, 1}, //5
    {0, 1, 0, 0, 0, 0, 0, 1}, //6
    {0, 0, 0, 1, 1, 1, 1, 1}, //7
    // {0, 0, 0, 0, 0, 0, 1, 1}, //8 --- 要修改
    // {0, 0, 0, 1, 1, 0, 0, 1}, //9 --- 要修改
    {0, 0, 0, 0, 0, 0, 0, 1}, //8
    {0, 0, 0, 0, 1, 0, 0, 1}, //9
    {0, 0, 0, 1, 0, 0, 0, 1}, //A
    {1, 1, 0, 0, 0, 0, 0, 1}, //b
    {0, 1, 1, 0, 0, 0, 1, 1}, //C
    {1, 0, 0, 0, 0, 1, 0, 1}, //d
    {0, 1, 1, 0, 0, 0, 0, 1}, //E
    {0, 1, 1, 1, 0, 0, 0, 1}, //F
    {1, 1, 1, 1, 1, 1, 1, 0}, //DOT = 16
    {1, 1, 1, 1, 1, 1, 0, 1}, //MINUS= 17
    {1, 1, 1, 1, 1, 1, 1, 1}, // 18
    {0, 0, 0, 0, 0, 0, 1, 0}, //19 -- 0.
    {1, 0, 0, 1, 1, 1, 1, 0}, //20 -- 1.
    {0, 0, 1, 0, 0, 1, 0, 0}, //21 -- 2.
    {0, 0, 0, 0, 1, 1, 0, 0}, //22 -- 3.
    {1, 0, 0, 1, 1, 0, 0, 0}, //23 -- 4.
    {0, 1, 0, 0, 1, 0, 0, 0}, //24 -- 5.
    {0, 1, 0, 0, 0, 0, 0, 0}, //25 -- 6.
    {0, 0, 0, 1, 1, 1, 1, 0}, //26 -- 7.
    {0, 0, 0, 0, 0, 0, 0, 0}, //27 -- 8. 
    {0, 0, 0, 0, 1, 0, 0, 0}, //28 -- 9.
    {0, 0, 0, 1, 0, 0, 0, 0}, //29 -- A.
    {1, 1, 0, 0, 0, 0, 0, 0}, //30 -- B.
    {0, 1, 1, 0, 0, 0, 1, 0}, //31 -- C.
    {1, 0, 0, 0, 0, 1, 0, 0}, //32 -- D.
    {0, 1, 1, 0, 0, 0, 0, 0}, //33 -- E.
    {0, 1, 1, 1, 0, 0, 0, 0} // 34 -- F.
  };
  //BLANK =18
  if ( digit > 34)return;
  for (unsigned int x = 0; x < 8; x++) {
    digitalWrite( digitalPin + x, abcdefgh[digit][x] );
  }
}


//指定位显示给定数字函数
void display(unsigned int wei, unsigned int digit) {
  int BLANK = 18;
  for (int x = 0; x <= 3; x++) {
    digitalWrite(weiPin + x, LOW); // 数字位引脚置低平
  }
  displayDigital(BLANK); //调用函数关闭所有显示字段
  digitalWrite(weiPin + wei - 1 , HIGH); //选择位显引脚，置高电平

  displayDigital(digit);//调用函数位显数字字段
  delay(1);//指定位的数字显示时间
  // 小于人的视觉效果，即可正确的每位显示不同的数据
}
